(function (angular,$) {
    var app=angular.module("couponProductApp",["ngSanitize"]);
    // app.service("couponsService",function () {
    //     this.getJsonp=function (url,cbFn) {
    //         var jsonpname="jsonp"+Math.random().toString().substring(5);
    //         window[jsonpname]=function (data) {
    //             cbFn(data)
    //         };
    //         var script=document.createElement("script");
    //         script.src=url+"?callback="+jsonpname;
    //         document.body.appendChild(script);
    //     }
    // })
    app.controller("couponProductCtrl",function ($scope,$http,$location) {
        var arr=$location.$$absUrl.split("?");
        var arr2=arr[1].split("&");
        var o={};
        for(var i=0;i<arr2.length;i++) {
            var temp=arr2[i].split("=");
            o[temp[0]]=temp[1];
        }
        $scope.title=decodeURI(o.title);
        var id=o.id;
        var url="http://139.199.192.48:9090/api/getcouponproduct?couponid="+id;
        $http({
            method:"get",
            url:url
        })
            .then(function (data) {
                $scope.couponProductData=data.data;
                $scope.maxid=$scope.couponProductData.result[$scope.couponProductData.result.length-1].couponProductId;
                $scope.minid=$scope.couponProductData.result[0].couponProductId;
            },function (error) {

            });
        $scope.getId=function (id) {
            $scope.id=id;
            for(var key in $scope.couponProductData.result) {
                if($scope.id==$scope.couponProductData.result[key].couponProductId) {
                    $scope.Img=$scope.couponProductData.result[key].couponProductImg;
                }
            }
        }
        $scope.pre=function () {
            if($scope.id<$scope.minid+1) {
                $(".firstInfo").css("display","block")
                $scope.id=$scope.minid+1;
            }
            $(".lastInfo").css("display","none")
            $scope.id--;
            for(var key in $scope.couponProductData.result) {
                if($scope.id==$scope.couponProductData.result[key].couponProductId) {
                    $scope.Img=$scope.couponProductData.result[key].couponProductImg;
                }
            }
        };
        $scope.next=function () {
            $(".firstInfo").css("display","none")
            if($scope.id>$scope.maxid-1) {
                $(".lastInfo").css("display","block")
                $scope.id=$scope.maxid-1;
            }
            $scope.id++;
            for(var key in $scope.couponProductData.result) {
                if($scope.id==$scope.couponProductData.result[key].couponProductId) {
                    $scope.Img=$scope.couponProductData.result[key].couponProductImg;
                }
            }
        };
    });
    $(".list").on("click","#a_list",function () {
        $('.popup').fadeIn(1000);
    });
    $(".popup").on("click",function () {
        $(".popup").fadeOut(1000);
        $(".firstInfo").css("display","none")
        $(".lastInfo").css("display","none");
    })
    $(".popup #layer").on("click",function(e){
        e.stopPropagation();
    });
    $(".popup .left").on("click",function(e){
        e.stopPropagation();
    });
    $(".popup .right").on("click",function(e){
        e.stopPropagation();
    });
})(angular,jQuery)